/*
 * ReturnNode.cpp
 *
 *  Created on: 22/nov/2010
 *      Author: computer
 */

#include "DerivationTree.h"
#include "ReturnInstruction.h"

ReturnNode::ReturnNode(const AutoPointer<NodeTree>& _returnNode) : NodeTree_CRTP<ReturnNode>(), returnNode(_returnNode) { }

ReturnNode::ReturnNode(const ReturnNode& copy) : NodeTree_CRTP<ReturnNode>(copy), returnNode(copy.returnNode) { }

bool ReturnNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	returnNode->execute(LVM);
	TreeExpression::ReturnInstruction* returnInstruction = new TreeExpression::ReturnInstruction();
	returnInstruction->setSon(LVM->top());
	LVM->pop();
	LVM->push( AutoPointer<TreeExpression::Expression>(returnInstruction) );
	return true;
}
